from selenium.webdriver.common.by import By

from util.page_base import PageBase


class PageLogin(PageBase):

    def __init__(self, driver, base_url):
        PageBase.__init__(self, driver, base_url)

    def input_zhanghao(self, zhanghao):
        loc = By.NAME, "login_info"
        self.clearAndInput(loc, zhanghao)

    def input_pwd(self, pwd):
        loc = By.NAME, "password"
        self.clearAndInput(loc, pwd)

    def click_login(self):
        loc = By.CSS_SELECTOR, "input[type='submit'][value='登录']"
        self.click(loc)

    def assert_true(self):
        loc_nicenH2 = By.CSS_SELECTOR, "div.user_info > h2"
        # 获取昵称h2标签的文本内容（去掉首尾空格）
        # "laodon，欢迎光临"
        return self.getEleText(loc_nicenH2)

    def assert_error(self):
        loc_nicenH2 = By.CSS_SELECTOR, "form div[class='prompt']"
        return self.getEleText(loc_nicenH2)
